package com.bluefish.bltuan.module.user;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.bluefish.bltuan.module.Category;
import com.bluefish.bltuan.module.Image;
import com.bluefish.bltuan.module.shop.TuanGou;
import com.bluefish.bltuan.tools.user.UserRight;

@Entity
@Table(name = "Customer")
public class User extends AbstractUser {
    /**
     * 
     */
    private static final long serialVersionUID = 4662879873954118885L;

    private String            email;

    private String            phone;

    private String            address;

    private String            appendix;

    @Column(nullable = true)
    private boolean           activated        = false;

    @ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    private List<TuanGou>     tuangous;

    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Image             portrait;

    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Category          city;

    private String            activeCode;

    public Category getCity() {
        return city;
    }

    public void setCity(Category city) {
        this.city = city;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Image getPortrait() {
        return portrait;
    }

    public void setPortrait(Image portrait) {
        this.portrait = portrait;
    }

    public String getAppendix() {
        return appendix;
    }

    public void setAppendix(String appendix) {
        this.appendix = appendix;
    }

    public boolean isActivated() {
        return activated;
    }

    public void setActivated(boolean activated) {
        this.activated = activated;
    }

    public List<TuanGou> getTuangous() {
        return tuangous;
    }

    public void setTuangous(List<TuanGou> tuangous) {
        this.tuangous = tuangous;
    }

    public void activate() {
        setActivated(true);
    }

    public void freeze() {
        setActivated(false);
    }

    public void setRight() {
        setUserRight(UserRight.NORMAL);
    }

    public void setActiveCode(String activeCode) {
        this.activeCode = activeCode;
    }

    public String getActiveCode() {
        return activeCode;
    }
}
